import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/test',
    component: () => import('@/views/test'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    meta: { title: '主页', icon: 'icon-pingmu' },
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/home/home/index'),
        meta: { title: '主页', icon: 'icon-pingmu' }
      },
      {
        path: 'editUserInfo',
        name: 'EditUserInfo',
        component: () => import('@/views/home/edit-user-info/index'),
        meta: { title: '编辑信息', icon: '' },
        hidden: true
      },
      {
        path: 'myfollow',
        name: 'Myfollow',
        component: () => import('@/views/home/my-follow/index'),
        meta: { title: '我的关注', icon: '' },
        hidden: true
      },
      {
        path: 'myfans',
        name: 'Myfans',
        component: () => import('@/views/home/my-fans/index'),
        meta: { title: '我的粉丝', icon: '' },
        hidden: true
      },
      {
        path: 'visited-histroy',
        name: 'Visited-histroy',
        component: () => import('@/views/home/visited-histroy/index'),
        meta: { title: '历史访问', icon: '' },
        hidden: true
      },
      {
        path: 'muban-choose',
        name: 'Muban-choose',
        component: () => import('@/views/home/muban-choose/index'),
        meta: { title: '模板选择', icon: '' },
        hidden: true
      },
      {
        path: 'news-center',
        redirect: '/news-center/news',
        component: () => import('@/views/home/news-center/index'),
        meta: { title: '消息中心', icon: '' },
        hidden: true,
        children: [
          {
            path: 'news',
            name: 'news',
            component: () => import('@/views/home/news-center/news/index'),
            hidden: true
          },
          {
            path: 'add-request',
            name: 'Add-request',
            component: () => import('@/views/home/news-center/add-request/index'),
            meta: { title: '添加问答', icon: '' },
            hidden: true
          }
        ]
      }

    ]
  },
  {
    path: '/account-info',
    component: Layout,
    redirect: '/account-info/index',
    meta: { title: '账户信息', icon: 'icon-24gl-wallet' },
    children: [
      {
        path: 'index',
        name: 'index',
        component: () => import('@/views/account-info/account/index'),
        meta: { title: '账户信息', icon: 'icon-24gl-wallet' }
      },
      {
        path: 'order-detail',
        name: 'OrderDetail',
        component: () => import('@/views/account-info/order-detail/index'),
        meta: { title: '订单详情', icon: 't' },
        hidden: true
      },
      {
        path: 'order-pay',
        name: 'OrderPay',
        component: () => import('@/views/account-info/order-pay/index'),
        meta: { title: '订单支付', icon: '' },
        hidden: true
      }
    ]
  },
  {
    path: '/model-info',
    component: Layout,
    name: 'model-info',
    redirect: '/model-info/data-overview',
    meta: { title: '模型信息', icon: 'icon-moxingliebiao' },
    children: [
      {
        path: 'data-overview',
        name: 'data-overview',
        component: () => import('@/views/model-info/data-overview/index'),
        meta: { title: '数据概览', icon: '' }
      },
      {
        path: 'model-list',
        name: 'model-list',
        component: () => import('@/views/model-info/model-list/index'),
        meta: { title: '模型列表', icon: '' }
      },
      {
        path: 'infomercial',
        name: 'infomercial',
        component: () => import('@/views/model-info/infomercial/index'),
        meta: { title: '广告机位', icon: '' },
        hidden: true
      },
      {
        path: 'add-model',
        name: 'add-model',
        component: () => import('@/views/model-info/add-model/index'),
        meta: { title: '新增模型', icon: '' },
        hidden: true
      },
      {
        path: 'edit-model',
        name: 'edit-model',
        component: () => import('@/views/model-info/edit-model/index'),
        meta: { title: '编辑模型', icon: '' },
        hidden: true
      },
      {
        path: 'model-detail',
        name: 'model-detail',
        component: () => import('@/views/model-info/model-detail/index'),
        meta: { title: '模型详情', icon: '' },
        hidden: true
      },
      {
        path: 'my-image',
        name: 'my-image',
        component: () => import('@/views/model-info/my-image/index'),
        meta: { title: '我的形象', icon: '' }
      },
      {
        path: 'knowledge-base',
        name: 'knowledge-base',
        component: () => import('@/views/model-info/knowledge-base/index'),
        meta: { title: '我的知识库', icon: '' }
      },
      {
        path: 'task-center',
        name: 'taskCenter',
        component: () => import('@/views/model-info/task-center/index'),
        meta: { title: '任务中心', icon: '' }
      },
      {
        path: 'reserve-task',
        name: 'reserve-task',
        component: () => import('@/views/model-info/task-center/reserve-task'),
        meta: { title: '重启任务', icon: '' },
        hidden: true
      }
    ]
  },
  {
    path: '/common-function',
    component: Layout,
    name: 'common-function',
    redirect: '/common-function/data-overview',
    meta: { title: '常用功能', icon: 'icon-fenlei' },
    children: [
      {
        path: 'card-template',
        name: 'card-template',
        component: () => import('@/views/home/muban-choose/index'),
        meta: { title: '名片模板', icon: '' }
      },
      {
        path: 'subscribe-manage',
        name: 'subscribe-manage',
        component: () => import('@/views/common-function/subscribe-manage/index'),
        meta: { title: '预约管理', icon: '' }
      },
      {
        path: 'subscribe-setting',
        name: 'subscribe-setting',
        component: () => import('@/views/common-function/subscribe-manage/setting'),
        meta: { title: '预约设置', icon: '' }
      },
      {
        path: 'my-subscribe',
        name: 'my-subscribe',
        component: () => import('@/views/common-function/my-subscribe/index'),
        meta: { title: '我的预约', icon: '' }
      },
      {
        path: 'video-manage',
        name: 'video-manage',
        component: () => import('@/views/common-function/video-manage/index'),
        meta: { title: '视频管理', icon: '' }
      },
      {
        path: 'add-video',
        name: 'add-video',
        component: () => import('@/views/common-function/video-manage/add-video/index'),
        hidden: true,
        meta: { title: '添加视频', icon: '' }
      },
      {
        path: 'edit-video',
        name: 'edit-video',
        component: () => import('@/views/common-function/video-manage/edit-video/index'),
        hidden: true,
        meta: { title: '修改视频', icon: '' }
      },
      {
        path: 'add-series',
        name: 'add-series',
        component: () => import('@/views/common-function/video-manage/add-series/index'),
        hidden: true,
        meta: { title: '添加合集', icon: '' }
      },
      {
        path: 'series-details',
        name: 'series-details',
        component: () => import('@/views/common-function/video-manage/series-details/index'),
        hidden: true,
        meta: { title: '合集详情', icon: '' }
      },
      {
        path: 'edit-series',
        name: 'edit-series',
        component: () => import('@/views/common-function/video-manage/edit-series/index'),
        hidden: true,
        meta: { title: '编辑合集', icon: '' }
      }

    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
